<template>
  <div class="container">
    <div class="header">
      <div class="left">
        <div>
          <img class="logo" src="@/assets/logo.png" />
        </div>
        <div @click="$router.push('/')" class="text">
          &ensp;全球货物，随你到处跑
        </div>
      </div>
      <div class="right">
        <div style="margin-top: -2px" class="menu_item">
          <MessageIcon></MessageIcon>
        </div>
        <div style="margin-top: -2px" class="menu_item" @click="screenClick">
          <el-icon style="vertical-align: middle; font-style: normal" :size="18"
            ><FullScreen
          /></el-icon>
        </div>
        <div class="menu_item menu_aliem">
          <el-dropdown
            trigger="hover"
            @command="empMenu.dropDownCommand"
            class
            size="middle"
            append-to-body
          >
            <div class="el-dropdown-link">
              {{ empMenu.employee?.RealName }}
            </div>
            <template #dropdown>
              <el-dropdown-menu class="menu_dropdown">
                <el-dropdown-item icon="el-icon-user" command="userinfo"
                  >个人设置</el-dropdown-item
                >
                <el-dropdown-item
                  divided
                  icon="el-icon-close"
                  command="outLogin"
                  >退出登录</el-dropdown-item
                >
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>
    </div>
    <div class="main-content">
      <div class="sidebarMail">
        <div class="sidebar__collapse" @click="slidetoggle">
          <el-icon v-if="layout.isCollapse" :size="20" color="#7F7F7F"
            ><Expand
          /></el-icon>
          <el-icon v-else :size="20" color="#7F7F7F"><Fold /></el-icon>
        </div>
        <el-menu
            :default-active="mainMenu.currentActive"
            class="el-menu-vertical-demo"
          >
            <MenuItemTree
              v-for="menu in mainMenu.childrenMenu?.Children"
              :key="menu.Id"
              :menu="menu"
              :choose="tab.clickMenuItem"
            ></MenuItemTree>
          </el-menu>
      </div>
      <div class="router-view">
        <!-- tab栏 start -->
        <!-- <el-tabs
          v-model="tab.activeTab"
          size="small"
          type="card"
          class="outer-tab"
          @tab-remove="tab.removeTab"
          @tab-click="tab.tabClick"
          :ref="(v) => (tab.tabRef = v)"
        >
          <el-tab-pane
            v-for="(tabItem, idx) in tab.tabs"
            :label="tabItem.title"
            :name="tabItem.route"
            :key="tabItem.route"
          >
            <template #label>
              <v-contextmenu :ref="tabItem.route">
                <v-contextmenu-item
                  @click="(ev) => tab.onTabRemove(tabItem.route, ev)"
                  >关闭</v-contextmenu-item
                >
                <v-contextmenu-item
                  @click="(ev) => tab.closeOtherTabs(tabItem.route, ev)"
                  >关闭其他菜单</v-contextmenu-item
                >
                <v-contextmenu-item
                  @click="(ev) => tab.closeRightTabs(tabItem.route, ev)"
                  >关闭右侧菜单</v-contextmenu-item
                >
              </v-contextmenu>
              <div
                class="tab-dragable-item"
                :idx="idx"
                v-contextmenu:[tabItem.route]
              >
                {{ tabItem.title }}
                <span
                  @click="(ev) => tab.onTabRemove(tabItem.route, ev)"
                  class="el-icon-close"
                ></span>
              </div>
            </template>
          </el-tab-pane>
        </el-tabs> -->

        <div v-loading="!layout.isLoadOver" class="router-view-content">
          <template v-if="layout.isLoadOver">
            <router-view v-slot="{ Component, route }">
              <keep-alive :ref="(v) => (tab.keepAliveNode = v)">
                <component :key="route.fullPath" :is="Component" />
              </keep-alive>
            </router-view>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import MessageIcon from "@/components/message/MessageIcon.vue";
import { FullScreen } from "@element-plus/icons";
import screenfull from "screenfull";
import tabRef from "@/composables/useTab";
import mainMenuRef from "@/composables/useMainMenu";
import employeeRef from "@/composables/useEmployee";
import { useStore, Store } from "vuex";
import { useRoute, useRouter } from "vue-router";
import { reactive } from "vue";

const store = useStore();
const router = useRouter();

const layout = reactive({
  isLoadOver: true,
  isCollapse: false,
});

// tab页相关
const tab = tabRef(store, router);
// 菜单相关
const mainMenu = mainMenuRef(router, tab.gotoRoute);
// 员工相关 (右上角)
const empMenu = employeeRef(store, router);

const screenClick = () => {
  screenfull.toggle();
};
const dropDownCommand = () => {};
const slidetoggle = () => {
  layout.isCollapse = !layout.isCollapse;
};
const handleOpen = (key, keyPath) => {
  console.log(key, keyPath);
};
const handleClose = (key, keyPath) => {
  console.log(key, keyPath);
};
</script>

<style lang="scss" scoped>
$header-height: 60px;
.container {
  width: 100%;
  height: 100%;
  min-width: $screen-min-width;
  ::v-deep(.el-overlay) {
    // z-index: 1950 !important;
  }
}

.header {
  width: 100%;
  height: $header-height;
  line-height: $header-height;
  display: flex;
  position: relative;
  // z-index: 2031;
  // box-shadow: 0 1px 3px 0 hsl(0deg 0% 42% / 15%);
  justify-content: space-between;
  background-color: #262626;
  color: #ffffff;
  padding: 0 8px 0 16px;
  // 头部左侧
  .left {
    display: flex;
    .logo {
      // width: 50px;
      vertical-align: middle;
    }
    .text {
      font-size: 14px;
    }

    .menu_icon {
      display: flex;
      width: 50px;
      height: 50px;
      background-color: #3388ff;
      color: #fff;
      text-align: center;
      margin-right: 10px;
      cursor: pointer;

      img {
        width: 30px;
        margin: 0 auto;
      }
    }
  }
  // 头部右侧
  .right {
    display: flex;
    padding-right: 10px;
    .menu_hover {
      cursor: pointer;
    }
    .menu_item {
      font-size: 13px;
      padding: 0px 10px;
      line-height: 60px;
      cursor: pointer;
    }
    .menu_icon {
      font-size: 17px;
    }
  }
}
.header:after {
  content: " ";
  display: block;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 1px;
  background-color: #595959;
  z-index: 100;
}

:deep(.internal-menu-drawer-overlay) {
  // z-index: 2030 !important;
}
::v-deep(.menu-drawer) {
  &.el-drawer {
    top: 50px;
    overflow: hidden;
    height: calc(100% - 50px);
  }

  .menu-container {
    display: flex;
    height: 100%;
    .left-menu {
      width: 240px;
      .menu-items {
        font-size: 12px;
      }
      .menu-item {
        width: 100%;
        color: #333;
        line-height: 48px;
        padding: 0 18px;
        box-sizing: border-box;
        cursor: pointer;
        &:hover {
          background-color: #f2f2f2;
        }
        &.hoverd {
          background-color: #f2f2f2;
        }
      }
      .user-menu-item {
        position: relative;
        border-bottom: 1px solid #e2e2e2;
        .arrow {
          position: absolute;
          color: #dedede;
          right: 10px;
          font-size: 16px;
          top: 16px;
        }
      }
    }
    .right-menu {
      min-width: 441px;
      padding-top: 32px;
      padding-left: 32px;
      padding-bottom: 7px;
      flex: 1;
      display: flex;
      box-shadow: 0 1px 4px 0 rgb(0 0 0 / 20%);
      background-color: #f7f7f7;
      height: 100%;
      position: relative;

      .close-drawer {
        position: absolute;
        right: 10px;
        top: 20px;
        font-size: 20px;
        cursor: pointer;
      }
    }
  }
}
.main-content {
  display: flex;
  // $header-height
  height: calc(100% - 60px);

  .toggle_left {
    position: absolute;
    top: 40%;
    cursor: pointer;
    right: -2px;
    z-index: 9;
  }
  .toggle_change {
    display: none;
  }

  ::v-deep(.children-menu) {
    position: relative;
    min-width: 180px;
    width: 180px;
    height: 100%;
    background-color: #f2f3f5;
    transition: min-width 0.3s ease-out, width 0.3s ease-out;
    border-right: 1px solid #e4e7ed;
    overflow-x: hidden;
    &.menu_change {
      width: 0;
      min-width: 0;
      transition: min-width 0.3s ease-out, width 0.3s ease-out;
    }
    .menu-title {
      color: #3c4144;
      margin-left: 20px;
      font-size: 14px;
      height: 56px;
      line-height: 56px;
      font-weight: 700;
    }
    .el-menu {
      background-color: #f5f5f5;
    }
    .el-menu-instance:hover {
      color: #409eff;
      background: #f5f5f5;
    }
    .el-menu-instance.is-active {
      // color: #303133;
      background-color: #eaeaea;
    }
    .el-submenu__title:hover {
      background-color: rgb(204, 204, 204);
    }
    // .el-menu-instance:hover {
    //   background-color: rgb(204, 204, 204);
    // }
    .el-sub-menu .el-menu-item {
      padding: 0px;
      min-width: auto;
    }
  }
  .toggle_right {
    position: absolute;
    top: 43%;
    cursor: pointer;
    z-index: 9;
  }
  .router-view {
    overflow: auto;
    height: 100%;
    width: 100%;
    flex: 1;

    :deep(.el-tabs--card > .el-tabs__header) {
      margin-bottom: 0;
    }
  }
  .router-view-content {
    flex: 1;
    overflow: auto;
    height: calc(100% - 30px);
    width: 100%;
    :deep(.el-overlay) {
      // z-index: 2103 !important;
    }
  }
}
.full-menu-items {
  display: flex;
  flex: 1;
  /* height: calc(100% - 50px); */
  height: 100vh;
  flex-wrap: wrap;
  max-width: 800px;
  overflow-y: auto;
}
::v-deep(.full-menu-item) {
  width: 220px;
  .full-menu-item-title {
    color: #333;
    font-size: 12px;
    font-weight: 600;
    line-height: 32px;
    margin-bottom: 8px;
    margin-left: 23px;
  }
  .el-tree {
    background-color: #f7f7f7;
  }
  .el-tree-node__label {
    font-size: 12px;
    color: #555;
  }
  .el-tree-node__content:hover {
    background-color: #eaeaea;
  }
}

::v-deep(.el-menu-vertical-demo) {
  &.el-menu {
    border-right: 0px;
  }
  .el-menu-item {
    height: 40px;
    line-height: 40px;
    opacity: 0.85;
    background-color: #f2f3f5;
    &:hover {
      opacity: 1;
      background-color: #f7f8fa;
      color: #409eff;
    }
    &.is-active {
      opacity: 1;
      background-color: #f7f8fa;
    }
  }

  .el-sub-menu {
    .el-sub-menu__title {
      height: 40px;
      line-height: 40px;
      &:hover {
        opacity: 1;
        background-color: #f7f8fa;
        color: #409eff;
      }
    }

    opacity: 0.85;
    background-color: #f2f3f5;
    &.is-opened {
      opacity: 1;
    }
  }
}

.menu_dropdown {
  width: 130px;
  box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.15);
  ::v-deep(.el-dropdown-menu__item) {
    padding: 0px 32px !important;
    padding-left: 12px !important;
    font-size: 12px;
    line-height: 28px;
  }
  ::v-deep(.el-dropdown-menu__item:not(.is-disabled):hover) {
    background-color: #eff4ff;
    color: #5e95ff;
  }
}
// 自定义标签栏
.outer-tab {
  width: 100%;
  height: 30px;
  background-color: white;
  overflow: hidden;

  ::v-deep(.el-tabs__item, .el-tabs__item:last-child) {
    height: 29px;
    line-height: 29px;
    // width:85px;
    padding: 0 10px !important;
    text-align: center !important;
  }
  ::v-deep(.is-active) {
    background: #f7f8fa;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
  ::v-deep(.el-tabs__nav-scroll) {
    padding: 0 17px;
  }
  ::v-deep(.el-tabs__nav-next) {
    line-height: 30px;
  }
  ::v-deep(.el-tabs__nav-prev) {
    line-height: 30px;
  }
  ::v-deep(.el-icon-close) {
    width: 14px !important;
  }
}
.tab-bar {
  :deep(.el-tabs__nav-scroll) {
    padding-left: 15px;
  }
}
.el-dropdown-link {
  display: inline-block;
  border-radius: 50%;
  overflow: hidden;
  background: #5e95ff;
  width: 24px;
  height: 24px;
  line-height: 24px;
  color: #ffffff;
  text-align: center;
  font-size: 13px;
}
.menu_aliem {
  display: flex;
  align-items: center;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 210px;
}
.sidebar__collapse {
  width: 100%;
  height: 40px;
  min-height: 40px;
  display: flex;
  -webkit-box-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  transition: font-size 0.15s cubic-bezier(0.215, 0.61, 0.355, 1),
    margin 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  color: #7f7f7f;
  align-items: center;
  border-bottom: 1px solid #595959;
  cursor: pointer;
  font-size: 20px;
}
.sidebarMail {
  background-color: #262626;
}
</style>
